<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<script type="text/javascript" src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#submit").click(function(){
            var token = getSessionStorage('vat_login_token');
            $.ajax({
                url: "hello/sayHello",
                crossDomain: true,
                type: "post",
                ContentType: 'text/plain',
                dataType: "json",
                data: {
                    "token":token
                },
                success: function (data) {
                    if (data.status == "S") {
                        $("#result").attr('value',data.data);
                    } else if (data.status == "T") {
                        $("#result").attr('value',data.data);
                }
                },
                error: function (err, a, b) {
                    console.log(err);
                }
            });
        });

        $("#addUser").click(function(){
            var token = getSessionStorage('vat_login_token');

            var id = document.getElementById('id').value
            var username = document.getElementById('username').value
            var password = document.getElementById('password').value
            var address = document.getElementById('address').value

            $.ajax({
                url: "user/addUser",
                crossDomain: true,
                type: "post",
                ContentType: 'text/plain',
                dataType: "json",
                data: {
                    "token":token,
                    "id":id,
                    "username":username,
                    "password":password,
                    "address":address,
                },
                success: function (data) {
                    if (data.status == "S") {
                        $("#result").attr('value',data.data);
                    } else if (data.status == "T") {
                        $("#result").attr('value',data.data);
                    }
                },
                error: function (err, a, b) {
                    console.log(err);
                }
            });
        });




    });
    function getSessionStorage (name) {
        var value = document.cookie
        if (value) {
            return value
        } else {
            return ''
        }
    }

</script>
<body>
<form>
    这是首页
    <button type="button" id="submit">请求后台</button>
    <input type="text" id="result" value='' ><br>
    添加一个用户 ：<button type="button" id="addUser">添加</button><br>
    名字：<input type="text" id="id"  ><br>
    名字：<input type="text" id="username"  ><br>
    密码：<input type="text" id="password"  ><br>
    地址：<input type="text" id="address"  ><br>

</form>
</body>
</html>
